#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

double round(double n){
	//found empirically: truncating past the last 2 digits is the way to go
	//it doesn't seem to be absolutely perfect but it got accepted so it's good enough for me
	return trunc(n*100)/100;
}

double findCash(const vector<double>& amounts){
	//find avg.
	double average = accumulate(amounts.begin(), amounts.end(), 0.0)/amounts.size();
	//find diffecence for each amount
	//add up the positive diference
	double posTotal = 0.0;
	double negTotal = 0.0;
	for(size_t i = 0; i < amounts.size(); ++i){
		double diff = round(amounts[i] - average);
		if(diff > 0)
			posTotal += diff;
		else
			negTotal -= diff;
	}
	return (posTotal > negTotal) ? posTotal : negTotal;
}

int main(){
	int vals;
	cin >> vals;
	while(vals != 0){
		vector<double> current;
		for(int i = 0; i < vals; ++i){
			double tmp;
			cin >> tmp;
			current.push_back(tmp);
		}
		cout.precision(2);
		cout << "$" << fixed << findCash(current) << endl;

		cin >> vals;
	}

}
